package com.jd.util;

import com.github.qcloudsms.SmsMultiSender;
import com.github.qcloudsms.SmsMultiSenderResult;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;

import java.util.ArrayList;

/**
 * 短信API
 *
 * @author 朱子龙 2018年3月19日下午2:19:34
 */
public class SmsServiceUtil {
	// 腾讯云配置信息
	static final Integer appid = 1400475757;

	static final String appkey = "91363e5c8c182ba69f36393fc89643b4";

	/**
	 * 单发模板短信
	 *
	 * @param smsId
	 * @param mobile
	 * @param params
	 *
	 * @author 朱子龙 2018年3月21日 下午1:43:52
	 * @return
	 */
	public static SmsSingleSenderResult txSendSms(Integer smsId, String mobile,
                                                  ArrayList<String> params) {
        try {
            SmsSingleSender sender = new SmsSingleSender(appid, appkey);
            SmsSingleSenderResult result = sender.sendWithParam("86",
                    mobile, smsId, params, "不凡电竞", "", "");
            String gbk = new String(result.errMsg.getBytes("UTF-8"), "gbk"); 
	   		 System.out.println(gbk);
	   		 String utf8 = new String(gbk.getBytes("gbk"), "utf-8");
	   		System.out.println(utf8+"====================================");
            //System.out.println(new String().getBytes(srcBegin, srcEnd, dst, dstBegin);           
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

	/**
	 * 群发模板短信
	 *
	 * @param smsId
	 * @param params
	 *
	 * @author 朱子龙 2018年3月21日 下午1:44:11
	 */
	public static void txMultiSendSms(Integer smsId,
			ArrayList<String> phoneNumbers, ArrayList<String> params) {
		try {
			SmsMultiSender sender = new SmsMultiSender(appid, appkey);
			SmsMultiSenderResult result = sender.sendWithParam("86",
					phoneNumbers, smsId, params, "", "", "");
			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
